// pages/user/login/login.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    username:'',
    password:''
  },
  login(){
    const app = getApp()
    wx.request({
      url: app.apiUrl + "/users/login",
      method:"POST",
      data:{
        "username": this.data.username,
        "password": this.data.password
      },
      success: res=>{
        console.log(res)
        if(res.data.code!=1){
          wx.showToast({
            title: res.data.msg,
            icon:"error"
          })
        }else{
          wx.setStorageSync('token', res.data.data.token)
          wx.showToast({
            title: '登录成功',
            success:res=>{
               wx.reLaunch({
                 url: '/pages/user/index/index',
                 success:res=>{
                
                 }
               })
            }
          })
        }
      }
    })
  }
  
})